<?php 
/**
 *  Por Federico Pisarello - SisDev Software (c) 2013 - Buenos Aires, Argentina.
 * 	fpisarello@gmail.com
 */

require("includes/funciones.inc.php");

session_start();
if(!isset($_SESSION['nombreUsuario']))
	exit();

function searchABMCheques()
{
	require("includes/constants.php");
	require("includes/datatables_db/Datatables.php");

	$datatables = new Datatables();

	$datatables
				->select('idCheque, nroCheque, banco, fechaEmision, fechaVto, importe')
				->from('cheques')
				->edit_column('fechaEmision','$1','formatoFecha(fechaEmision)')
				->edit_column('fechaVto','$1','formatoFecha(fechaVto)');

	return $datatables->generate();
}

function consultaCheque()
{
	require("includes/constants.php");
	
	$DB = NewADOConnection('mysqlt');
	$DB->Connect();
	$DB->Execute("SET NAMES utf8;");
	//$DB->debug=true;
	
	$strsQL = "SELECT c.*, rd.idRecibo FROM cheques c 
				INNER JOIN recibos_detalle rd ON c.idCheque = rd.idCheque
				WHERE
					c.idCheque = ".$_REQUEST["idCheque"];
	
	$rsCheques = $DB->Execute($strsQL); // execute query
	
	if(!$rsCheques->EOF){
		
		$joCheque->data['nroRecibo'] = $rsCheques->fields("idRecibo");
		$joCheque->data['fechaEmisionCheque'] = formatoFecha($rsCheques->fields("fechaEmision"));
		$joCheque->data['fechaVtoCheque'] = formatoFecha($rsCheques->fields("fechaVto"));
		$joCheque->data['importeCheque'] = $rsCheques->fields("importe");
		$joCheque->data['sucursalCheque'] = $rsCheques->fields("sucursal");
		$joCheque->data['bancoCheque'] = $rsCheques->fields("banco");
		$joCheque->data['nroCheque'] = $rsCheques->fields("nroCheque");
		$joCheque->data['firmanteCheque'] = $rsCheques->fields("firmante");
		$joCheque->data['cuitFirmanteCheque'] = $rsCheques->fields("cuitFirmante");
	
		return json_encode($joCheque->data);
	}
	else
		return json_encode(array());
}

switch($_REQUEST['accion'])
{
	case "search":
		echo searchABMCheques();
		break;
	case "CONSULT":
		echo consultaCheque();
		break;
}
?>